﻿/*
==================================================================
    注意：此文件为Auto代码，不可手动修改【在用绳维保】
==================================================================
*/

namespace Services
{
    /// <summary>
    /// Auto在用绳维保
    /// </summary>
    public abstract class AutoUsingWireropeKeepMapping : BaseMapping<UsingWireropeKeep, UsingWireropeKeepModel, UsingWireropeKeepFilterModel>
    {
        public AutoUsingWireropeKeepMapping(ICurrentUser currentUser)
            : base(currentUser) { }

        #region 读数据
        /// <summary>
        /// 读数据，从Entity对象转成Model对象
        /// </summary>
        /// <param name="entity">Entity对象</param>
        /// <returns></returns>
        public override UsingWireropeKeepModel Entity2Model(UsingWireropeKeep entity)
        {
            UsingWireropeKeepModel model = new UsingWireropeKeepModel();

            model.UsingWireropeKeepID = entity.UsingWireropeKeepID;
            model.GroupInfoID = entity.GroupInfoID;
            model.UsingWireropeID = entity.UsingWireropeID;
            model.WireropeKeepTypeID = entity.WireropeKeepTypeID;
            model.DoPosition = entity.DoPosition;
            model.CompanyName = entity.CompanyName;
            model.UserName = entity.UserName;
            model.DoDate = entity.DoDate;
            model.Remark = entity.Remark;
            model.Pic_ImgsList = entity.Pic_Imgs.GetFileList();
            model.Attr_FilesList = entity.Attr_Files.GetFileList();
            model.CreateUserID = entity.CreateUserID;
            model.CreateUserName = entity.CreateUserName;
            model.CreateDate = entity.CreateDate;

            return model;
        }
        #endregion

        #region 写数据
        /// <summary>
        /// 写数据，从Model对象转换成Entity对象
        /// </summary>
        /// <param name="model">ViewModel对象</param>
        /// <returns></returns>
        public override UsingWireropeKeep Model2Entity(UsingWireropeKeepModel model)
        {
            UsingWireropeKeep entity = new UsingWireropeKeep();

            entity.UsingWireropeKeepID = model.UsingWireropeKeepID;
            entity.GroupInfoID = model.GroupInfoID;
            entity.UsingWireropeID = model.UsingWireropeID;
            entity.WireropeKeepTypeID = model.WireropeKeepTypeID;
            entity.DoPosition = model.DoPosition;
            entity.CompanyName = model.CompanyName;
            entity.UserName = model.UserName;
            entity.DoDate = model.DoDate;
            entity.Remark = model.Remark;
            entity.Pic_Imgs = model.Pic_ImgsList.GetFileString();
            entity.Attr_Files = model.Attr_FilesList.GetFileString();
            entity.CreateUserID = model.CreateUserID;
            entity.CreateUserName = model.CreateUserName;
            entity.CreateDate = model.CreateDate;

            return entity;
        }
        #endregion

        #region 搜索条件转换
        /// <summary>
        /// 搜索条件转换，从FilterModel对象转换成Where对象
        /// </summary>
        /// <param name="filterModel">FilterModel对象</param>
        /// <returns></returns>
        public override Expressionable<UsingWireropeKeep> FilterModel2Where(UsingWireropeKeepFilterModel filterModel)
        {
            var where = base.FilterModel2Where(filterModel);

            //编号
            if (filterModel._UsingWireropeKeepID.HasValue)
            {
                where = where.And(x => x.UsingWireropeKeepID == filterModel._UsingWireropeKeepID.Value);
            }
            if (filterModel._UsingWireropeKeepIDs.IsNotEmpty() && filterModel._UsingWireropeKeepIDs.Count > 0)
            {
                where = where.And(x => filterModel._UsingWireropeKeepIDs.Contains(x.UsingWireropeKeepID));
            }
            if (filterModel._NotUsingWireropeKeepIDs.IsNotEmpty() && filterModel._NotUsingWireropeKeepIDs.Count > 0)
            {
                where = where.And(x => !filterModel._NotUsingWireropeKeepIDs.Contains(x.UsingWireropeKeepID));
            }

            //集团
            if (filterModel._GroupInfoID.HasValue)
            {
                where = where.And(x => x.GroupInfoID == filterModel._GroupInfoID.Value);
            }
            if (filterModel._GroupInfoIDs.IsNotEmpty() && filterModel._GroupInfoIDs.Count > 0)
            {
                where = where.And(x => filterModel._GroupInfoIDs.Contains(x.GroupInfoID));
            }
            if (filterModel._NotGroupInfoIDs.IsNotEmpty() && filterModel._NotGroupInfoIDs.Count > 0)
            {
                where = where.And(x => !filterModel._NotGroupInfoIDs.Contains(x.GroupInfoID));
            }

            //在用绳
            if (filterModel._UsingWireropeID.HasValue)
            {
                where = where.And(x => x.UsingWireropeID == filterModel._UsingWireropeID.Value);
            }
            if (filterModel._UsingWireropeIDs.IsNotEmpty() && filterModel._UsingWireropeIDs.Count > 0)
            {
                where = where.And(x => filterModel._UsingWireropeIDs.Contains(x.UsingWireropeID));
            }
            if (filterModel._NotUsingWireropeIDs.IsNotEmpty() && filterModel._NotUsingWireropeIDs.Count > 0)
            {
                where = where.And(x => !filterModel._NotUsingWireropeIDs.Contains(x.UsingWireropeID));
            }

            //维保类型
            if (filterModel._WireropeKeepTypeID.HasValue)
            {
                where = where.And(x => x.WireropeKeepTypeID == filterModel._WireropeKeepTypeID.Value);
            }
            if (filterModel._WireropeKeepTypeIDs.IsNotEmpty() && filterModel._WireropeKeepTypeIDs.Count > 0)
            {
                where = where.And(x => filterModel._WireropeKeepTypeIDs.Contains(x.WireropeKeepTypeID));
            }
            if (filterModel._NotWireropeKeepTypeIDs.IsNotEmpty() && filterModel._NotWireropeKeepTypeIDs.Count > 0)
            {
                where = where.And(x => !filterModel._NotWireropeKeepTypeIDs.Contains(x.WireropeKeepTypeID));
            }

            //实施部门
            if (!string.IsNullOrEmpty(filterModel._CompanyName))
            {
                where = where.And(x => x.CompanyName.Contains(filterModel._CompanyName));
            }
            if (!string.IsNullOrEmpty(filterModel._CompanyNameEqual))
            {
                where = where.And(x => x.CompanyName == filterModel._CompanyNameEqual);
            }

            //实施人员
            if (!string.IsNullOrEmpty(filterModel._UserName))
            {
                where = where.And(x => x.UserName.Contains(filterModel._UserName));
            }
            if (!string.IsNullOrEmpty(filterModel._UserNameEqual))
            {
                where = where.And(x => x.UserName == filterModel._UserNameEqual);
            }

            //实施日期
            if (filterModel._DoDate.HasValue)
            {
                where = where.And(x => x.DoDate == filterModel._DoDate.Value);
            }
            if (filterModel._DoDate_Begin.HasValue)
            {
                where = where.And(x => x.DoDate >= filterModel._DoDate_Begin.Value);
            }
            if (filterModel._DoDate_End.HasValue)
            {
                where = where.And(x => x.DoDate < filterModel._DoDate_End.Value.AddDays(1));
            }

            //创建人姓名
            if (!string.IsNullOrEmpty(filterModel._CreateUserName))
            {
                where = where.And(x => x.CreateUserName.Contains(filterModel._CreateUserName));
            }
            if (!string.IsNullOrEmpty(filterModel._CreateUserNameEqual))
            {
                where = where.And(x => x.CreateUserName == filterModel._CreateUserNameEqual);
            }

            //创建时间
            if (filterModel._CreateDate.HasValue)
            {
                where = where.And(x => x.CreateDate == filterModel._CreateDate.Value);
            }
            if (filterModel._CreateDate_Begin.HasValue)
            {
                where = where.And(x => x.CreateDate >= filterModel._CreateDate_Begin.Value);
            }
            if (filterModel._CreateDate_End.HasValue)
            {
                where = where.And(x => x.CreateDate < filterModel._CreateDate_End.Value.AddDays(1));
            }

            return where;
        }
        #endregion
    }
}

